import 'package:bruno/bruno.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_shipper/http/NoLoadingGetApi.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/StringEncapsulation.dart';
import '../../l10n/messages.dart';

class BlackList extends StatefulWidget {
  const BlackList({super.key});

  @override
  State<BlackList> createState() => _BlackListState();
}

class _BlackListState extends State<BlackList> {
  List titleList=["发布危险品","发送律师函被退回，多次联系不结算运费","恶意拖欠运费"];
  List dataList=[];
  String writeStr="";
  int pageNum=1;
  FocusNode focusNode = FocusNode();
  BrnSearchTextController scontroller = BrnSearchTextController();
  TextEditingController textController = TextEditingController();
  @override
  void initState() {
    textController.addListener(() {
      if (focusNode.hasFocus) {
        if (!BrunoTools.isEmpty(textController.text)) {
          scontroller.isClearShow = true;
          scontroller.isActionShow = true;
        }
      }
    });
    focusNode.addListener(() {
      if (focusNode.hasFocus) {
        if (!BrunoTools.isEmpty(textController.text)) {
          scontroller.isClearShow = true;
        }
      }
    });
    super.initState();
    getBlackList();
  }
  Future _onRefresh() async {
    //......实现刷新逻辑

    setState(() {
      pageNum=1;
    });
    getBlackList();
  }
  void onReachBottom() {
    setState(() {
      pageNum=pageNum+1;
      getBlackList();
    });

    // 在这里可以执行加载更多数据的逻辑
  }
  void getBlackList(){
    NoLoadinggetApiManager.getData(
      context,
      "api/system/system/blacklist/page",
      {"current":pageNum,'userType':"DRIVER","size":20,"phoneNum":writeStr},
          (responseData)  {
        setState(() {
          if(pageNum==1) {
            dataList = responseData['data']['records'];
          }else{
            if(responseData['data']['records'].isEmpty){
              pageNum=pageNum-1;
            }else{
              dataList.addAll(responseData['data']['records']);
            }
          }

        });
      },
    );
  }
  @override
  Widget build(BuildContext context) {

    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){Navigator.pop(context);},),
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(messages["黑名单"],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
      ),
      body: ListView(
        children: [

          BrnSearchText(
            focusNode: focusNode,
            controller: textController,
            searchController: scontroller..isActionShow = false,
              outSideColor:MyColors.backgreyColor,
              textInputType:TextInputType.number,
              innerColor:Colors.white,
              borderRadius:BorderRadius.all(const Radius.circular(30.0)),
              hintText:"输入手机号搜索黑名单司机",
            onTextClear: () {
              debugPrint('sss');
              return false;
            },
            onActionTap: () {
              scontroller.isClearShow = false;
              scontroller.isActionShow = false;
              focusNode.unfocus();

            },
            onTextCommit: (text) {

            },
            onTextChange: (text) {
             setState(() {
               writeStr=text;
               getBlackList();
             });
            },
          ),
      EasyRefresh(
        header:
        ClassicHeader(
          dragText: '下拉刷新',
          armedText: '准备释放',
          readyText: '加载中...',
          processingText: '加载中...',
          processedText: '刷新成功',
          noMoreText: '暂无更多',
          failedText: '刷新失败',
          messageText: '刷新时间 %T',
        ),
        footer: ClassicFooter(
          dragText: '加载更多',
          armedText: '准备释放',
          readyText: '加载中...',
          processingText: '加载中...',
          processedText: '加载成功',
          noMoreText: '暂无更多',
          failedText: '加载失败',
          messageText: '加载时间 %T',
        ),
        onRefresh: _onRefresh,
        onLoad:dataList.length>pageNum*20-1?onReachBottom:null,
        child:
          Container(
            height: screenSize.height-160.h,
            child: ListView.builder(
                itemCount: dataList.length,
                itemBuilder: (BuildContext context, int index) {
                  return Column(
                    children: [
                  Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w),
                  padding: EdgeInsets.only(left:10.w,right: 10.w,top: 10.h,bottom: 20.h),
                  // height: 100.h,
                  decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only( topLeft: Radius.circular(10),topRight: Radius.circular(10)),

                  ),

                  child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                        constraints: BoxConstraints(
                          maxWidth:screenSize.width-40.w, // 限制文本最大宽度
                        ),
                        child:
                        Text(dataList[index]['blackDesc'],style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ),
                  SizedBox(height:10.h,),


                  Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                  Text("司机姓名"+" "+dataList[index]['realName'],style: TextStyle(color: MyColors.textColor,fontSize:MyFontSizes.smallText.sp),),
                  Text("手机号"+" "+dataList[index]['phoneNum'],style: TextStyle(color: MyColors.textColor,fontSize:MyFontSizes.smallText.sp),),
                  ],
                  ),

                  BrnDashedLine(
                  dashedLength: 3,
                  dashedThickness: 1.h,
                  axis: Axis.horizontal,
                  color: MyColors.hintColor,
                  dashedOffset: 10.h,

                  contentWidget: Container(
                  width: screenSize.width-20.h,
                  height: 1,
                  ),
                  ),




                  ],

                  ),
                  ),
                      Container(
                        margin: EdgeInsets.only(left: 10.w,right: 10.w,bottom: 8.h),
                        padding: EdgeInsets.only(left: 10.w,right: 10.w,bottom: 8.h),
                        width: screenSize.width-20.w,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.only( bottomRight: Radius.circular(10),bottomLeft: Radius.circular(10)),

                        ),
                        // height: 40.h,
                        child: Text("身份证"+" "+dataList[index]['idcard'].substring(0, 3)+"************"+dataList[index]['idcard'].substring(15),style: TextStyle(color: MyColors.textColor,fontSize:MyFontSizes.smallText.sp),),

                      ),

                    ],
                  );

                   }


            ),
          ),
      ),

        ],
      ),
    );
  }
}
